package com.example.model23.test3;

import java.util.HashMap;
import java.util.Map;

// 工厂管理类
public class VehicleFactoryManager {
    private final Map<String, VehicleFactory> factories = new HashMap<>();

    public void registerFactory(String type, VehicleFactory factory) {
        factories.put(type, factory);
    }

    public Vehicle createVehicle(String type) {
        VehicleFactory factory = factories.get(type);
        if (factory == null) {
            throw new IllegalArgumentException("Unknown vehicle type: " + type);
        }
        //汽车工厂，生产
        return factory.create();
    }
}